<template>
  <div class="app-container">
    <el-table border v-loading="loading"  :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="报销人" align="center" prop="userId"/>
            <el-table-column label="报销人姓名" align="center" prop="userName"/>-->
      <el-table-column label="发放日期" align="center" prop="grantDate" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.grantDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发放金额" align="center" prop="grantMoney"  />
      <el-table-column label="发放公司" align="center" prop="companyName" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.company" :value="scope.row.companyName" />
        </template>
      </el-table-column>
      <!--<el-table-column label="发放记录" align="center" prop="companyId"/>-->
      <el-table-column align="center" label="发放记录" prop="companyId" width="200">
        <template slot-scope="scope">
          <image-preview :src="scope.row.companyId" height="60px" width="40px"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--<el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:GoodsReimbursementDetail:edit']">修改</el-button>-->
          <el-popconfirm :title="`确认删除 `+scope.row.id+` 数据项？`" @confirm="handleDelete(scope.row)"
            style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <goodsReimbursementDetail-form ref="form" @ok="getList"></goodsReimbursementDetail-form>
  </div>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'
  import GoodsReimbursementDetailForm from '@/views/develop/goodsReimbursementDetail/module/GoodsReimbursementDetailForm'

  export default {
    name: "GoodsReimbursementDetailList",
    dicts: ['company'],
    components: {
      GoodsReimbursementDetailForm,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        reimburseId: "",
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 发放打款明细信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          reimburseId: null,
          userId: null,
          userName: null,
          grantDate: null,
          grantMoney: null,
          companyId: null,
          companyName: null,
          status: null,
        },
        url: {
          list: '/goodsReimbursementDetail/goodsReimbursementDetail/list',
          remove: '/goodsReimbursementDetail/goodsReimbursementDetail/',
          export: '/goodsReimbursementDetail/goodsReimbursementDetail/export',
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getListByReimburseId(reimburseId) {
        this.reimburseId = reimburseId;
        this.getList();
      },
      /** 查询发放打款明细信息管理列表 */
      getList() {
        this.loading = true;
        this.queryParams.reimburseId = this.reimburseId;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
          this.$emit('ok');
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `goodsReimbursementDetail_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
